package com.ruoyi.web.controller.user;

import com.ruoyi.user.domain.dto.UserLoginDTO;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.web.service.SysLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mrj
 * @eo.api-type http
 * @eo.groupName 用户信息
 * @eo.path /user
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class PlanetUserController extends BaseController {

    private final SysLoginService sysLoginService;

    /**
     * @eo.name 登录
     * @eo.url /login
     * @eo.method post
     * @eo.request-type formdata
     * @param userLoginDTO 用户登录信息
     * @return AjaxResult
     */
    @PostMapping("/login")
    public AjaxResult login(UserLoginDTO userLoginDTO) throws Exception {
        AjaxResult ajax = AjaxResult.success();
        // 生成令牌
        String token = sysLoginService.login(userLoginDTO.getUsername(),
                userLoginDTO.getPassword(), userLoginDTO.getCode());
        ajax.put(Constants.TOKEN, token);
        return ajax;
    }
}